import React from 'react';
import { Select } from 'antd';
import { useTranslation } from 'react-i18next';
import type { SelectProps } from 'antd';

const LanguageSwitcher: React.FC = () => {
  const { t, i18n } = useTranslation();
  const currentLanguage = i18n.language;

  const handleLanguageChange: SelectProps['onChange'] = (value) => {
    i18n.changeLanguage(value as string);
    localStorage.setItem('language', value as string);
  };

  const options: SelectProps['options'] = [
    {
      value: 'zh-CN',
      label: '中文'
    },
    {
      value: 'en-US',
      label: 'English'
    }
  ];

  return (
    <Select
      value={currentLanguage}
      onChange={handleLanguageChange}
      options={options}
      style={{ width: 80 }}
      placeholder={t('common.select')}
      showSearch={false}
    />
  );
};

export default LanguageSwitcher;